package com.api.shopapi.mapper;



import com.api.shopapi.entity.InterfaceTime;
import com.api.shopapi.entity.dto.InterfaceTimeDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface InterfaceTimeMapper {

    @Insert("insert into  interface_time " +
            "(" +
            "InterfaceTimeCode, " +
            "Interface, " +
            "UseTime, " +
            "CreateTime" +
            ") " +
            "VALUES " +
            "(" +
            "#{interfaceTime.InterfaceTimeCode} ," +
            "#{interfaceTime.Interface} ," +
            "#{interfaceTime.UseTime} ," +
            "#{interfaceTime.CreateTime} ) ")
    int insert(@Param("interfaceTime") InterfaceTime interfaceTime);



    @Select("select *,sum(UseTime)/count(Interface) as AverageTime,count(Interface) as Number  from interface_time    group by  Interface order by AverageTime desc ")
    List<InterfaceTimeDTO> getList();


    @Delete("delete  from interface_time  where InterfaceTimeCode=#{interfaceTimeCode}   ")
    int delete(@Param("interfaceTimeCode") String interfaceTimeCode);

    @Select("select * from interface_time where InterfaceTimeCode=#{interfaceTimeCode} limit 1 ")
    InterfaceTime getByInterfaceTimeCode(@Param("interfaceTimeCode") String interfaceTimeCode);


    @Select("select * from interface_time where Interface=#{interfaces} ")
    List<InterfaceTime> getByInterface(@Param("interfaces") String interfaces);




}